package main

import (
	"fmt"
	"regexp"
)
//正则表达式
func main() {
	context1 := "3.14 123123 .68 haha 1.0 abc 6.66 123."

	//MustCompile解析并返回一个正则表达式，如果成功返回，改regexp就可用于匹配文本
	exp1 := regexp.MustCompile(`\d+\.\d+`)
	//返回保管正则表达式所有不重叠的匹配结果的[]string切片.如果未匹配到,会返回nil
	result1 := exp1.FindAllStringSubmatch(context1, -1)
	fmt.Printf("%v\n", result1)
	fmt.Printf("\n-------------------------------------------\n\n")

	context2 := `
		<title>标题</title>
		<div>你过来啊</div>
		<div>hello mike</div>
		<div>你大爷</div>
		<body>呵呵</body>
	`
	exp2 := regexp.MustCompile(`<div>(.*?)</div>`)

	result2 := exp2.FindAllStringSubmatch(context2, -1)
	fmt.Printf("%v\n", result2)
	fmt.Printf("\n-------------------------------------------\n\n")

	context3 := `
		<title>标题</title>
		<div>你过来啊</div>
		<div>hello
		mike
		go</div>
		<div>你大爷</div>
		<body>呵呵</body>
	`
	result3 := exp2.FindAllStringSubmatch(context3, -1)
	fmt.Printf("%v\n", result3)
	fmt.Printf("\n-------------------------------------------\n\n")

	exp4 := regexp.MustCompile(`<div>(?s:(.*?))</div>`)

	result4 := exp4.FindAllStringSubmatch(context3, -1)
	fmt.Printf("%v\n", result4)
	fmt.Printf("\n-------------------------------------------\n\n")

	for _,text := range result4 {
		fmt.Println(text[0])
		fmt.Println(text[1])
		fmt.Println("================\n")
	}
}
